#pragma once

/*
	@author: Nicolas Santamaria
	@date  : 16/09/08
	@what  : Socket Server
*/

#ifndef __TCPSOCKETSERVER_H__
#define __TCPSOCKETSERVER_H__

// The following macros define the minimum required platform.  The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
// your application.  The macros work by enabling all features available on platform versions up to and 
// including the version specified.

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif

#define MAJOR_VERSION 0
#define MINOR_VERSION 1

#include <ace/SOCK_Acceptor.h>
#include <ace/SOCK_Stream.h>
#include "ace/INET_Addr.h"
//#include <ace/IOStream.h>
#include "Parser.h"

#include <ace/Task.h>


namespace Network
{

	class SocketServer
	{
		virtual void open(unsigned short p_port) = 0;
	};

	class TCPSocketServer : public SocketServer
	{
	private:
		BasicParser*					m_parser;

		ACE_INET_Addr					m_peerAddr;
		ACE_SOCK_Acceptor				m_acceptor;
		ACE_SOCK_Stream					m_stream;
	public:

		TCPSocketServer();//BasicParser* p_parser);
		~TCPSocketServer();

		void setParser(BasicParser* p_parser);
		void open(unsigned short p_port = ACE_DEFAULT_SERVER_PORT);
		int receive();
	};

	class ServerThread : public ACE_Task<ACE_MT_SYNCH>
	{
	private:
		bool m_stop;
		int svc();
		void stop();

	public :
		ServerThread();
		void close();
		
	};

};

#endif